using System.Collections;
using System.Collections.Generic;

namespace Components
{
    /// <summary>
    /// Classes implementing this interface allows subset of items to be extracted
    /// </summary>
    /// <typeparam name="TItem">The type of the item</typeparam>
    public interface IPageable<TItem> : IEnumerable<TItem>
    {
        int Count { get; }

        IEnumerable<TItem> GetAll();

        IEnumerable<TItem> GetPage(int offset, int count);
    }


    /// <summary>
    /// Base class for implementing the <see cref="IPageable&lt;TItem&gt;" /> interface
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class PageableBase<T> : IPageable<T>
    {
        public abstract int Count { get; }

        public abstract IEnumerable<T> GetAll();

        public abstract IEnumerable<T> GetPage(int offset, int count);

        public IEnumerator<T> GetEnumerator()
        {
            return GetAll().GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}